import os
import logging.handlers

# 基本路径
BASE_URL = "http://ihrm-test.itheima.net"

# 项目根路径
# print(os.path.abspath(__file__))
# print(os.path.dirname(os.path.abspath(__file__)))
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
print(BASE_DIR)

# 存放请求头数据的容器
headers_data = {
    "Content-Type": "application/json",
    "Authorization": "Bearer xxx"
}


# 初始化日志配置
def init_log_config():
    # 创建日志器对象
    logger = logging.getLogger()
    logger.setLevel(logging.INFO)

    # 创建处理器对象(控制台、日志文件)
    sh = logging.StreamHandler()
    file_path = BASE_DIR + "/log/ihrm.log"
    fh = logging.handlers.TimedRotatingFileHandler(file_path, when="midnight",
                                                   interval=1, backupCount=15,
                                                   encoding="UTF-8")
    # 创建格式化器
    fmt = "%(asctime)s %(levelname)s [%(name)s] [%(filename)s(%(funcName)s:%(lineno)d)] - %(message)s"
    formatter = logging.Formatter(fmt)

    # 把格式化器添加到处理中
    sh.setFormatter(formatter)
    fh.setFormatter(formatter)

    # 把处理器添加到日志器中
    logger.addHandler(sh)
    logger.addHandler(fh)


if __name__ == '__main__':
    init_log_config()
    logging.info("普通信息")
    logging.error("错误信息")
